How do you link a time stamp to a cell using a userform button control? [migrated]

Posted by Chad Cochrane on Super User See other posts from Super User or by Chad Cochrane
Published on 2012-06-04T22:21:51Z Indexed on 2012/06/04 22:42 UTC
Read the original article Hit count: 232

Filed under:
|
|
|

Hello fellow VB Developers/Users/Hobbyists/What-Have-You! I have a user form that has two buttons: 1. Start 2. Stop

When I press start, I would like it to record the current time with this format: (dd/mm/yy hh:nn:ss:) in a specific column.

Then when I press the Stop Button I would like it to record the time again in the cell next to it.

Then if I press start Again I would like it to record below the first cells current record. Basically I am building a timer to record data to see how long certain tasks take.

I will post the excel file and provide more information were necessary.

Thanks for any help provided.

CURRENT CODE


Public runTimer As Double
Public startTime As Date
Dim counter As Date

Sub setStart()

counter = 0
startTime = Now
runTimer = Now + TimeSerial(0, 0, 1)
Application.OnTime runTimer, "setStart", , True

Set myTime = Sheet4.Range("F1")
Set timeRng = Sheet4.Range("C8:C100")
i = WorksheetFunction.CountA(timeRng)
i = i + 1

Cells(i, "C") = myTime
Sheet4.Cells(i, "C").NumberFormat = "yyyy/mm/dd HH:mm:ss"

If i >= 2 Then
Cells(i, "D8") = Cells(i, "C8") - Cells(i - 1, "C8")
Sheet4.Cells(i, "C").NumberFormat = "yyyy/mm/dd HH:mm:ss"
End If
Application.EnableEvents = False

End Sub

Sub setStop()

Application.OnTime runTimer, "setStop", , True

Set myTime = Sheet4.Range("F1")
Set timeRng = Sheet4.Range("D8:D100")
i = WorksheetFunction.CountA(timeRng)
i = i + 1

Application.EnableEvents = False
Cells(i, "D") = myTime
Sheet4.Cells(i, "D").NumberFormat = "yyyy/mm/dd HH:mm:ss"

End Sub

© Super User or respective owner

Related posts about microsoft-excel

Related posts about vba